		TITLE	INSTOUT - Copyright (C) 1994 SLR Systems

		INCLUDE	MACROS
		INCLUDE	IO_STRUC

		PUBLIC	INSTALL_OUTFILE


		.DATA

		EXTERNDEF	OUTFILE_NUMBER:DWORD,FIRST_OUTFILE_GINDEX:DWORD,LAST_OUTFILE_GINDEX:DWORD

		EXTERNDEF	OUTFILE_GARRAY:STD_PTR_S


		.CODE	FILEPARSE_TEXT


ALLOC_OUTFILE	PROC
		;
		;EAX IS FILE_LIST GINDEX, ECX IS PHYS
		;
		PUSHM	EDI,EBX,EAX

		MOV	EAX,SIZE OUTFILE_STRUCT
		TILLP2_POOL_ALLOC		;EAX
		MOV	EBX,EAX
		ASSUME	EBX:PTR OUTFILE_STRUCT

		INSTALL_POINTER_GINDEX	OUTFILE_GARRAY
		MOV	EDX,EAX
		MOV	EDI,EBX

		MOV	ECX,SIZE OUTFILE_STRUCT/4
		XOR	EAX,EAX
		REP	STOSD

		POP	EAX
		BITT	SKIP_OUTFILE_LINK
		MOV	[EBX]._OF_FILE_LIST_GINDEX,EAX
		MOV	EAX,OUTFILE_NUMBER
		JNZ	L6$

		MOV	[EBX]._OF_OUTFILE_NUMBER,EAX
		INC	EAX
		MOV	OUTFILE_NUMBER,EAX

		MOV	EAX,LAST_OUTFILE_GINDEX
		MOV	LAST_OUTFILE_GINDEX,EDX
		TEST	EAX,EAX
		JZ	L7$
		CONVERT	EAX,EAX,OUTFILE_GARRAY
		MOV	[EAX].OUTFILE_STRUCT._OF_NEXT_OUTFILE_ORDER,EDX
L6$:
		MOV	ECX,EBX
		POPM	EBX,EDI
		MOV	EAX,EDX
		RET

L7$:
		MOV	ECX,EBX
		POPM	EBX,EDI
		MOV	EAX,EDX
		MOV	FIRST_OUTFILE_GINDEX,EDX
		RET

ALLOC_OUTFILE ENDP

if	any_overlays

INSTALL_OUTFILE PROC
		;
		;AX:BX IS FILE_LIST ENTRY, RETURNS AX:BX LOG, DX PHYS
		;
		MOV	DX,AX
		MOV	SI,AX
		MOV	AX,BX
		MOV	DI,BX
		SHRI	AX,2			;AT LEAST DWORD ADDRESSES...
if	fg_os2
		SHRI	DX,4			;3 BITS WE DON'T CARE ABOUT, 1 INTO CARRY
else
		SUB	DX,OFF BLOCK_TABLE
		SHRI	DX,2			;1 BIT WE DON'T CARE ABOUT, 1 INTO CARRY
endif
		ADC	AX,AX
		SHR	DX,1
		ADC	AX,AX			;THAT IS TWO BITS SHIFTED OUT FOR DWORD BOUNDARY
		REPT	PAGE_SHIFT
		SHR	DX,1
		ADC	AX,AX
		ENDM
		AND	DX,OUTFILE_HASH_SIZE-1
		;
		;OK, AX HAS 16-BITS OF INFO, DX HAS AS MANY AS LEGAL
		;
		DIV	OUTFILE_HASH		;DX IS HASH VALUE
		SHLI	DX,2
		LDS	BX,OUTFILE_HASH_TABLE_PTR
		ADD	BX,DX
		LEA	BX,-_OF_NEXT_HASH[BX]
OUTFILE_NEXT:
		CMP	[BX]._OF_NEXT_HASH.SEGM,0
		JZ	DO_OUTFILE_INSTALL
		LDS	BX,_OF_NEXT_HASH[BX]
		MOV	DX,DS
		SYM_CONV_DS
		CMP	[BX]._OF_FILE_LIST.OFFS,DI
		JNZ	OUTFILE_NEXT
		CMP	[BX]._OF_FILE_LIST.SEGM,SI
		JNZ	OUTFILE_NEXT
		MOV	AX,DX
		MOV	DX,DS
		STC				;FAILED, ALREADY THERE
		RET

DO_OUTFILE_INSTALL:
		;
		;DS:BX GETS POINTER
		;
		PUSHM	DS,BX
		MOV	AX,SI
		MOV	BX,DI
		CALL	ALLOC_OUTFILE
		POPM	DI,DS
		MOV	[DI]._OF_NEXT_HASH.OFFS,BX
		MOV	[DI]._OF_NEXT_HASH.SEGM,AX
		RET

INSTALL_OUTFILE	ENDP

else

INSTALL_OUTFILE	EQU	(ALLOC_OUTFILE)

endif

		END

